<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="预归档档案名称" prop="fileArchiveName">
        <el-input
          v-model="queryParams.fileArchiveName"
          placeholder="请输入预归档档案名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预归档档案类型id" prop="archiveTypeId">
        <el-input
          v-model="queryParams.archiveTypeId"
          placeholder="请输入预归档档案类型id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="企业id()" prop="enterpriseId">
        <el-input
          v-model="queryParams.enterpriseId"
          placeholder="请输入企业id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门id()" prop="departmentId">
        <el-input
          v-model="queryParams.departmentId"
          placeholder="请输入部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="档案预归档申请人id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入档案预归档申请人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预归档档案地址" prop="fileArchiveAddress">
        <el-input
          v-model="queryParams.fileArchiveAddress"
          placeholder="请输入预归档档案地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预归档档案的所属案卷名称" prop="docName">
        <el-input
          v-model="queryParams.docName"
          placeholder="请输入预归档档案的所属案卷名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预归档档案的所属案卷编号" prop="docNumber">
        <el-input
          v-model="queryParams.docNumber"
          placeholder="请输入预归档档案的所属案卷编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预归档档案的保管期限" prop="saveTime">
        <el-input
          v-model="queryParams.saveTime"
          placeholder="请输入预归档档案的保管期限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否可以借阅，同档案表" prop="borrowState">
        <el-input
          v-model="queryParams.borrowState"
          placeholder="请输入是否可以借阅，同档案表"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保密等级，同档案表" prop="secrecyLevel">
        <el-select v-model="queryParams.secrecyLevel" placeholder="请选择保密等级，同档案表" clearable>
          <el-option
            v-for="dict in dict.type.secrecy_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="盒号" prop="boxNumber">
        <el-input
          v-model="queryParams.boxNumber"
          placeholder="请输入盒号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预归档的纸质档案现实存放地址" prop="location">
        <el-input
          v-model="queryParams.location"
          placeholder="请输入预归档的纸质档案现实存放地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批状态，只有0待审批、1正在审批、2审批完成" prop="shenpiState">
        <el-select v-model="queryParams.shenpiState" placeholder="请选择审批状态，只有0待审批、1正在审批、2审批完成" clearable>
          <el-option
            v-for="dict in dict.type.apply_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="档案预归档申请人所在企业的企业级档案主管的id，user_id" prop="enterpriseAdminId">
        <el-input
          v-model="queryParams.enterpriseAdminId"
          placeholder="请输入档案预归档申请人所在企业的企业级档案主管的id，user_id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="档案预归档申请人所在企业的企业级档案主管的审批意见，只有同意和不同意" prop="enterpriseAdminOpinion">
        <el-input
          v-model="queryParams.enterpriseAdminOpinion"
          placeholder="请输入档案预归档申请人所在企业的企业级档案主管的审批意见，只有同意和不同意"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="档案预归档申请人所在企业的企业级档案主管的备注说明" prop="enterpriseAdminNote">
        <el-input
          v-model="queryParams.enterpriseAdminNote"
          placeholder="请输入档案预归档申请人所在企业的企业级档案主管的备注说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:DFile:add']"
        >审批（放入操作栏）</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:DFile:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:DFile:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:DFile:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="DFileList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="档案预归档申请编号" align="center" prop="id" />
      <el-table-column label="预归档档案名称" align="center" prop="fileArchiveName" />
      <el-table-column label="预归档档案类型编号" align="center" prop="archiveTypeId" />
      <!-- <el-table-column label="企业编号" align="center" prop="enterpriseId" />
      <el-table-column label="通过企业编号查企业名称" align="center" prop="enterpriseName" /> -->
      <el-table-column label="部门编号" align="center" prop="departmentId" />
      <el-table-column label="部门名称" align="center" prop="departmentName" />
      <el-table-column label="档案预归档申请人编号" align="center" prop="userId" />
      <el-table-column label="档案预归档申请人姓名" align="center" prop="userId" />
      <el-table-column label="预归档档案内容" align="center" prop="fileArchiveContent" />
      <el-table-column label="预归档档案地址" align="center" prop="fileArchiveAddress" />
      <el-table-column label="预归档档案的所属案卷名称" align="center" prop="docName" />
      <el-table-column label="预归档档案的所属案卷编号" align="center" prop="docNumber" />
      <el-table-column label="预归档档案的保管期限" align="center" prop="saveTime" />
      <el-table-column label="是否可以借阅" align="center" prop="borrowState" />
      <el-table-column label="保密等级" align="center" prop="secrecyLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.secrecy_level" :value="scope.row.secrecyLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="盒号" align="center" prop="boxNumber" />
      <el-table-column label="预归档的纸质档案现实存放地址" align="center" prop="location" />
      <el-table-column label="审批状态（只有0待审批、1正在审批、2审批完成）" align="center" prop="shenpiState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.apply_status" :value="scope.row.shenpiState"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="企业级档案主管的编号" align="center" prop="enterpriseAdminId" />
      <el-table-column label="企业级档案主管的审批意见（只有同意和不同意）" align="center" prop="enterpriseAdminOpinion" />
      <el-table-column label="企业级档案主管的备注说明" align="center" prop="enterpriseAdminNote" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:DFile:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:DFile:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改档案预归档对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="预归档档案名称" prop="fileArchiveName">
          <el-text v-model="form.fileArchiveName" placeholder="请输入预归档档案名称" />
        </el-form-item>
        <el-form-item label="预归档档案类型" prop="archiveTypeId">
          <el-text v-model="form.archiveTypeId" placeholder="请输入预归档档案类型id" />
        </el-form-item>
        <!-- <el-form-item label="企业id" prop="enterpriseId">
          <el-input v-model="form.enterpriseId" placeholder="请输入企业id" />
        </el-form-item> -->
        <!-- <el-form-item label="部门id" prop="departmentId">
          <el-input v-model="form.departmentId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="档案预归档申请人id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入档案预归档申请人id" />
        </el-form-item>
        <el-form-item label="预归档档案内容">
          <editor v-model="form.fileArchiveContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="预归档档案地址" prop="fileArchiveAddress">
          <el-input v-model="form.fileArchiveAddress" placeholder="请输入预归档档案地址" />
        </el-form-item>
        <el-form-item label="预归档档案的所属案卷名称" prop="docName">
          <el-input v-model="form.docName" placeholder="请输入预归档档案的所属案卷名称" />
        </el-form-item>
        <el-form-item label="预归档档案的所属案卷编号" prop="docNumber">
          <el-input v-model="form.docNumber" placeholder="请输入预归档档案的所属案卷编号" />
        </el-form-item>
        <el-form-item label="预归档档案的保管期限" prop="saveTime">
          <el-input v-model="form.saveTime" placeholder="请输入预归档档案的保管期限" />
        </el-form-item>
        <el-form-item label="是否可以借阅，同档案表" prop="borrowState">
          <el-input v-model="form.borrowState" placeholder="请输入是否可以借阅，同档案表" />
        </el-form-item>
        <el-form-item label="保密等级，同档案表" prop="secrecyLevel">
          <el-radio-group v-model="form.secrecyLevel">
            <el-radio
              v-for="dict in dict.type.secrecy_level"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="盒号" prop="boxNumber">
          <el-input v-model="form.boxNumber" placeholder="请输入盒号" />
        </el-form-item>
        <el-form-item label="预归档的纸质档案现实存放地址" prop="location">
          <el-input v-model="form.location" placeholder="请输入预归档的纸质档案现实存放地址" />
        </el-form-item>
        <el-form-item label="审批状态，只有0待审批、1正在审批、2审批完成" prop="shenpiState">
          <el-radio-group v-model="form.shenpiState">
            <el-radio
              v-for="dict in dict.type.apply_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <el-form-item label="企业级档案主管的id，user_id" prop="enterpriseAdminId">
          <el-text v-model="form.enterpriseAdminId" placeholder="请输入档案预归档申请人所在企业的企业级档案主管的id，user_id" />
        </el-form-item>
        <el-form-item label="企业级档案主管的审批意见(下拉框只有同意和不同意）" prop="enterpriseAdminOpinion">
          <el-input v-model="form.enterpriseAdminOpinion" placeholder="请输入档案预归档申请人所在企业的企业级档案主管的审批意见，只有同意和不同意" />
        </el-form-item>
        <el-form-item label="企业级档案主管的备注说明" prop="enterpriseAdminNote">
          <el-input v-model="form.enterpriseAdminNote" placeholder="请输入档案预归档申请人所在企业的企业级档案主管的备注说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDFile, getDFile, delDFile, addDFile, updateDFile } from "@/api/system/DFile";

export default {
  name: "DFile",
  dicts: ['secrecy_level', 'apply_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 档案预归档表格数据
      DFileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fileArchiveName: null,
        archiveTypeId: null,
        enterpriseId: null,
        departmentId: null,
        userId: null,
        fileArchiveContent: null,
        fileArchiveAddress: null,
        docName: null,
        docNumber: null,
        saveTime: null,
        borrowState: null,
        secrecyLevel: null,
        boxNumber: null,
        location: null,
        shenpiState: null,
        enterpriseAdminId: null,
        enterpriseAdminOpinion: null,
        enterpriseAdminNote: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询档案预归档列表 */
    getList() {
      this.loading = true;
      listDFile(this.queryParams).then(response => {
        this.DFileList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fileArchiveName: null,
        archiveTypeId: null,
        enterpriseId: null,
        departmentId: null,
        userId: null,
        fileArchiveContent: null,
        fileArchiveAddress: null,
        docName: null,
        docNumber: null,
        saveTime: null,
        borrowState: null,
        secrecyLevel: null,
        boxNumber: null,
        location: null,
        createTime: null,
        shenpiState: null,
        enterpriseAdminId: null,
        enterpriseAdminOpinion: null,
        enterpriseAdminNote: null,
        createBy: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加档案预归档";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDFile(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改档案预归档";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDFile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDFile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除档案预归档编号为"' + ids + '"的数据项？').then(function() {
        return delDFile(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/DFile/export', {
        ...this.queryParams
      }, `DFile_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
